import io
import os.path

import aiofiles
import falcon

from WebBackend.middleware.virtualWorldGate_Chuche import login_require
from WebBackend.utils import mylog
from WebBackend.utils.render_template import render_template
import App_setting as setting


class Index:
    async def on_get(self, req, resp):
        mylog.info(f'Access from {req.remote_addr}')
        if os.path.exists(os.path.join(setting.path.dir_html_static_folder, 'index.html')):
            resp.content_type = "text/html"
            resp.text = render_template(
                'index.html',
                # login_required=login_require
            )
        else:
            resp.text='Hello, but index.html was not found'

    @staticmethod
    async def sing_redirect(req, resp):
        resp.location = '/'
        resp.status = falcon.HTTP_301

